 
package com.xbongbong.saas.domain.dao;

import com.xbongbong.paas.domain.entity.StageLogEntity;
import com.xbongbong.saas.domain.entity.CustomerStageLogEntity;
import com.xbongbong.saas.domain.entity.ext.StageLogEntityExt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
* @author autoGen
* @time 2018-06-06 19:45:16
*/
@Repository
@Mapper
public interface CustomerStageLogDao {

	Integer insert(CustomerStageLogEntity customerStageLog);
	Integer update(CustomerStageLogEntity customerStageLog);

	void insertBatch(List<CustomerStageLogEntity> customerStageLogList);
	Integer deleteByStageProcessIdAndDataIdIn(@Param("list") List<Long> dataIdIn, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("stageProcessId") Long stageProcessId, @Param("stageId") Long stageId);
	Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
	CustomerStageLogEntity getByKey (@Param("key") Long key, @Param("corpid") String corpid);

	List<CustomerStageLogEntity> findEntitys(@Param("param") Map<String, Object> param);
	Integer getEntitysCount(@Param("param") Map<String, Object> param);

	List<CustomerStageLogEntity> findStageLogWithoutStage();

    Double getStageAverageTime(@Param("param") Map<String, Object> param, @Param("currentTime") Integer currentTime);

    void deleteEntitys(@Param("param") Map<String, Object> searchParam);

	List<StageLogEntityExt> getAverageStayTime(@Param("param")Map<String ,Object> param);

	void updateBatch(@Param("list") List<CustomerStageLogEntity> updateList, @Param("corpid") String corpid);

	void updateBatch4Script(@Param("list") List<CustomerStageLogEntity> updateList);

	List<Map<String, Object>> getStageStatistic(@Param("param") Map<String, Object> map);

	Integer deleteBatch(@Param("list") List<StageLogEntity> stageLogEntityList, @Param("corpid") String corpid);

	/**
	 * 根据dataId 查找当前数据所处阶段
	 * @param corpid
	 * @param formId
	 * @param dataId
	 * @return
	 */
	CustomerStageLogEntity getIsNowStage(@Param("corpid") String corpid, @Param("formId") Long formId, @Param("dataId") Long dataId);

	Long getAvgStayTime(@Param("corpid") String corpid, @Param("stageProcessId") Long stageProcessId, @Param("stageId") Long stageId);

	List<Long> findUsedStageProcessId(@Param("corpid") String corpid, @Param("formId") Long formId, @Param("stageProcessIdIn") List<Long> stageProcessIdIn);
}